-
Notifications
You must be signed in to change notification settings - Fork 9.5k
feat(fetch): add SSRF protection and comprehensive security test suite #3180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(fetch): add SSRF protection and comprehensive security test suite #3180
Conversation
d0c9333 to
2892ae1
Compare
7e6a302 to
345a570
Compare
0e0769e to
a4ce0fc
Compare
7703e1e to
2a2c923
Compare
This PR adds Server-Side Request Forgery (SSRF) protection and a comprehensive security test suite to the fetch MCP server. - URL scheme validation (only http/https allowed) - Private IP range blocking (10.x, 172.16-31.x, 192.168.x, 127.x, etc.) - IPv6 private address blocking (::1, fe80::, fc00::, etc.) - Dangerous hostname blocking (localhost, metadata services, etc.) - DNS resolution validation to prevent DNS rebinding - Configurable via MCP_FETCH_ALLOW_PRIVATE_IPS env var - Whitelist support via MCP_FETCH_ALLOWED_PRIVATE_HOSTS - Configurable SSL verification via MCP_FETCH_SSL_VERIFY env var - Comprehensive SSL error handling with helpful messages - SSRF protection tests - Private IP blocking tests - Input validation tests - URL scheme validation tests - Integration tests - Edge case tests ```bash export MCP_FETCH_SSL_VERIFY=false export MCP_FETCH_ALLOW_PRIVATE_IPS=true export MCP_FETCH_ALLOWED_PRIVATE_HOSTS=internal.company.com,api.local ``` fix: address security review feedback - Disable follow_redirects to prevent SSRF bypass via open redirects - Add explicit IP obfuscation detection (decimal/octal/hex formats) - Fix SSL parsing to be fail-secure (only 'false' disables verification) - Clean up test headers (remove enterprise roleplay language) - Add comprehensive tests for IP obfuscation parsing fix: add octal integer IP parsing and fix test naming - Add octal integer format parsing (017700000001 = 127.0.0.1) - Rename SSL test to reflect fail-secure behavior (stays_enabled, not defaults_to_false) - Add tests for octal integer IP obfuscation
2a2c923 to
7aabbb4
Compare
|
This is an excellent and comprehensive approach to SSRF protection! The layered defense strategy and extensive test coverage show a deep understanding of the security requirements. What's done really well:
Security considerations:
Mitigation options:
🔒 Redirect handling - Does the fetch server follow HTTP redirects? If yes, an attacker could bypass SSRF protection: Should validate every URL in the redirect chain, or disable redirects entirely. 📋 Private IP bypass with octal/hex encoding - Does the IP parser handle these edge cases?
Python's Recommendation: This is production-ready for most use cases. For maximum security in high-risk environments, I'd suggest:
Really strong work on this — the 89-test suite and comprehensive IP range coverage are exemplary! |
Summary
This PR adds Server-Side Request Forgery (SSRF) protection and a comprehensive security test suite to the fetch MCP server.
Security Features Added
SSRF Protection
SSL Configuration
Test Suite (89 tests)
Configuration
Server Details
Motivation and Context
The fetch server can be exploited for SSRF attacks, allowing malicious actors to access internal services (cloud metadata endpoints, internal APIs, etc.). This PR adds comprehensive protection while maintaining flexibility for legitimate internal use cases through configuration options.
How Has This Been Tested?
Breaking Changes
None. All protections are backward compatible. Private IPs can be enabled via env var if needed.
Types of changes
Checklist
Additional context
This PR builds on #3179 which adds SSL verification configuration.